package dao.implementations.postgresql.Socio;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import dao.implementations.DBBase;
import dao.interfaces.Socio.IPautaEvaluacion;
import dao.transferObjects.Gae.CursoTO;
import dao.transferObjects.Gae.GaeTO;
import dao.transferObjects.Socio.PautaEvaluacionTO;
import dao.transferObjects.Socio.SocioTO;

public class PautaEvaluacionDB extends DBBase implements IPautaEvaluacion {

	public PautaEvaluacionDB(Connection connection)
	{
		this.conn = connection;
	}
	/*
	private static String CAMPOS_PAUTA = " rut_socio, id_gae, rut_gae, item_1, item_2, item_3, item_4, item_5, " +
										" item_6, item_7, item_8, item_9, item_10, item_11, item_12, item_13, " +
										" item_14, item_15, item_16, item_17, item_18, item_19, item_20, " +
										" item_21, item_22, item_23, item_24, item_25, item_26, item_27, " +
										" item_28, item_29, item_30, item_31, nuevamente, experiencia, " +
										" comentario, fecha_hora, nota ";
	*/
	private static String CAMPOS_PAUTA = " id_pauta, rut_socio, id_gae, rut_gae, item_1, item_2, item_3, " +
										" item_4, item_5, item_6, item_7, item_8, item_9, item_10, item_11, " +
										" item_12, item_13, item_14, item_15, item_16, item_17, item_18, " +
										" item_19, item_20, item_21, item_22, item_23, item_24, item_25, " +
										" item_26, item_27, item_28, item_29, item_30, item_31, nuevamente, " +
										" experiencia, comentario, fecha_hora, calidad, compromiso, vinculacion, " +
										" valoracion, ptje_nota, nota ";
	/*
	private static String SET_CAMPOS_PAUTA =   " item_1=?, item_2=?, item_3=?, "+
												" item_4=?, item_5=?, item_6=?, item_7=?, item_8=?, item_9=?, item_10=?, "+
												" item_11=?, item_12=?, item_13=?, item_14=?, item_15=?, item_16=?, "+
												" item_17=?, item_18=?, item_19=?, item_20=?, item_21=?, item_22=?, "+
												" item_23=?, item_24=?, item_25=?, item_26=?, item_27=?, item_28=?, "+
												" item_29=?, item_30=?, item_31=?, nuevamente=?, experiencia=?, "+
												" comentario=?, fecha_hora=?, nota=? ";
	*/
	private static String SET_CAMPOS_PAUTA =   " item_1=?, item_2=?, item_3=?, "+
												" item_4=?, item_5=?, item_6=?, item_7=?, item_8=?, item_9=?, item_10=?, "+
												" item_11=?, item_12=?, item_13=?, item_14=?, item_15=?, item_16=?, "+
												" item_17=?, item_18=?, item_19=?, item_20=?, item_21=?, item_22=?, "+
												" item_23=?, item_24=?, item_25=?, item_26=?, item_27=?, item_28=?, "+
												" item_29=?, item_30=?, item_31=?, nuevamente=?, experiencia=?, "+
												" comentario=?, fecha_hora=?, calidad=?, compromiso=?, vinculacion=?, " +
												" valoracion=?, ptje_nota=?, nota=? ";
	/*
	private static String SET_CAMPOS_PAUTA2 =   " rut_socio=?, id_gae=?, rut_gae=?, item_1=?, item_2=?, item_3=?, "+
												" item_4=?, item_5=?, item_6=?, item_7=?, item_8=?, item_9=?, item_10=?, "+
												" item_11=?, item_12=?, item_13=?, item_14=?, item_15=?, item_16=?, "+
												" item_17=?, item_18=?, item_19=?, item_20=?, item_21=?, item_22=?, "+
												" item_23=?, item_24=?, item_25=?, item_26=?, item_27=?, item_28=?, "+
												" item_29=?, item_30=?, item_31=?, nuevamente=?, experiencia=?, "+
												" comentario=?, fecha_hora=?, nota=? ";
	*/
	public PautaEvaluacionTO resultSet_a_PautaEvaluacionTO(ResultSet rs){
		PautaEvaluacionTO pauta = new PautaEvaluacionTO();
		try{
			pauta.setId_pauta(rs.getInt("id_pauta"));
			pauta.setRut_socio(rs.getInt("rut_socio"));
			pauta.setId_gae(rs.getInt("id_gae"));
			pauta.setRut_gae(rs.getInt("rut_gae"));
			
			pauta.setItem1(rs.getInt("item_1"));
			pauta.setItem2(rs.getInt("item_2"));
			pauta.setItem3(rs.getInt("item_3"));
			pauta.setItem4(rs.getInt("item_4"));
			pauta.setItem5(rs.getInt("item_5"));
			pauta.setItem6(rs.getInt("item_6"));
			pauta.setItem7(rs.getInt("item_7"));
			pauta.setItem8(rs.getInt("item_8"));
			pauta.setItem9(rs.getInt("item_9"));
			pauta.setItem10(rs.getInt("item_10"));
			
			pauta.setItem11(rs.getInt("item_11"));
			pauta.setItem12(rs.getInt("item_12"));
			pauta.setItem13(rs.getInt("item_13"));
			pauta.setItem14(rs.getInt("item_14"));
			pauta.setItem15(rs.getInt("item_15"));
			pauta.setItem16(rs.getInt("item_16"));
			pauta.setItem17(rs.getInt("item_17"));
			pauta.setItem18(rs.getInt("item_18"));
			pauta.setItem19(rs.getInt("item_19"));
			pauta.setItem20(rs.getInt("item_20"));
			
			pauta.setItem21(rs.getInt("item_21"));
			pauta.setItem22(rs.getInt("item_22"));
			pauta.setItem23(rs.getInt("item_23"));
			pauta.setItem24(rs.getInt("item_24"));
			pauta.setItem25(rs.getInt("item_25"));
			pauta.setItem26(rs.getInt("item_26"));
			pauta.setItem27(rs.getInt("item_27"));
			pauta.setItem28(rs.getInt("item_28"));
			pauta.setItem29(rs.getInt("item_29"));
			pauta.setItem30(rs.getInt("item_30"));
			
			pauta.setItem31(rs.getInt("item_31"));
			
			pauta.setNuevamente(rs.getBoolean("nuevamente"));
			pauta.setExperiencia(rs.getInt("experiencia"));
			pauta.setComentario(rs.getString("comentario"));
			pauta.setFechaHora(rs.getTimestamp("fecha_hora"));
			
			pauta.setCalidad(rs.getDouble("calidad"));
			pauta.setCompromiso(rs.getDouble("compromiso"));
			pauta.setVinculacion(rs.getDouble("vinculacion"));
			pauta.setValoracion(rs.getDouble("valoracion"));
			
			pauta.setPtje_nota(rs.getDouble("ptje_nota"));
			pauta.setNota(rs.getDouble("nota"));
		}
		catch (SQLException e){
			System.out.println("Error en "+this.getClass().getCanonicalName()+" -> resultSet_a_PautaEvaluacionTO : " + e.getMessage());
		}
		
		return pauta;
	}
	
	public int siguienteId_pauta(SocioTO socio, GaeTO gae){
		int resp = -1;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		String query =  " SELECT count(*) as id_pauta " +
						" FROM pauta_evaluacion " +
						" WHERE rut_socio=? AND id_gae=? AND rut_gae=? ";
		
		try{						
			pstmt = conn.prepareStatement(query);						
			
			pstmt.setInt(1, socio.getRut_socio());
			pstmt.setInt(2, gae.getId_gae());
			pstmt.setInt(3, gae.getRut_gae());
			
			rs = pstmt.executeQuery();
			
			if(rs.next())
				resp = rs.getInt("id_pauta")+1;
			
			rs.close();			
		}
		catch (SQLException sqle) {
			System.out.print("Error en PautaEvaluacionDB -> siguienteId_pauta() : " + sqle.getMessage());
		}
		finally{
			if (pstmt != null) {
		          try {
		               pstmt.close();
		               
		          } catch (SQLException e) {
		               e.printStackTrace();
		          }
			}
		}
		return resp;
	}
	
	@Override
	public int crearPautaEvaluacion(SocioTO socio, GaeTO gae) {
		PreparedStatement pstm = null;
		int result = 0;
		
		java.util.Date a = new java.util.Date();
		long lnMilisegundos = a.getTime();
		Timestamp tsCreacion = new Timestamp(lnMilisegundos);
		
		String query =  " INSERT INTO pauta_evaluacion( "+
						  CAMPOS_PAUTA + " )" +
						" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
		try{
			pstm = this.conn.prepareStatement(query);
			
			pstm.setInt(1, siguienteId_pauta(socio, gae));
			pstm.setInt(2, socio.getRut_socio());
			pstm.setInt(3, gae.getId_gae());
			pstm.setInt(4, gae.getRut_gae());
			
			pstm.setInt(5, -1);
			pstm.setInt(6, -1);
			pstm.setInt(7, -1);
			pstm.setInt(8, -1);
			pstm.setInt(9, -1);
			
			pstm.setInt(10, -1);
			pstm.setInt(11, -1);
			pstm.setInt(12, -1);
			pstm.setInt(13, -1);
			pstm.setInt(14, -1);
			
			pstm.setInt(15, -1);
			pstm.setInt(16, -1);
			pstm.setInt(17, -1);
			pstm.setInt(18, -1);
			pstm.setInt(19, -1);
			
			pstm.setInt(20, -1);
			pstm.setInt(21, -1);
			pstm.setInt(22, -1);
			pstm.setInt(23, -1);
			pstm.setInt(24, -1);
			
			pstm.setInt(25, -1);
			pstm.setInt(26, -1);
			pstm.setInt(27, -1);
			pstm.setInt(28, -1);
			pstm.setInt(29, -1);
			
			pstm.setInt(30, -1);
			pstm.setInt(31, -1);
			pstm.setInt(32, -1);
			pstm.setInt(33, -1);
			pstm.setInt(34, -1);
			
			pstm.setInt(35, -1);
			
			pstm.setBoolean(36, false);
			pstm.setInt(37, -1);
			pstm.setString(38, "");
			pstm.setTimestamp(39, tsCreacion);
			
			pstm.setDouble(40, 0.0);
			pstm.setDouble(41, 0.0);
			pstm.setDouble(42, 0.0);
			pstm.setDouble(43, 0.0);
			
			pstm.setDouble(44, 0.0);
			pstm.setDouble(45, 0.0);
			
			result = pstm.executeUpdate();
			pstm.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error en la clase PautaEvaluacionDB -> crearPautaEvaluacion -> "+ ex.getMessage());
		}		
		return result;
	}

	@Override
	public int modificarPautaEvaluacion(SocioTO socio, GaeTO gae, PautaEvaluacionTO pautaEvaluacion) {
		PreparedStatement pstm = null;
		int result = 0;
		
		java.util.Date a = new java.util.Date();
		long lnMilisegundos = a.getTime();
		Timestamp tsCreacion = new Timestamp(lnMilisegundos);
		
		String query =  " UPDATE pauta_evaluacion " +
						" SET "+ SET_CAMPOS_PAUTA +
						" WHERE rut_socio=? AND id_gae=? AND rut_gae=? AND id_pauta=?";
		try{
			pstm = this.conn.prepareStatement(query);
			
			pstm.setInt(1, pautaEvaluacion.getItem1());
			pstm.setInt(2, pautaEvaluacion.getItem2());
			pstm.setInt(3, pautaEvaluacion.getItem3());
			pstm.setInt(4, pautaEvaluacion.getItem4());
			pstm.setInt(5, pautaEvaluacion.getItem5());
			
			pstm.setInt(6, pautaEvaluacion.getItem6());
			pstm.setInt(7, pautaEvaluacion.getItem7());
			pstm.setInt(8, pautaEvaluacion.getItem8());
			pstm.setInt(9, pautaEvaluacion.getItem9());
			pstm.setInt(10, pautaEvaluacion.getItem10());
			
			pstm.setInt(11, pautaEvaluacion.getItem11());
			pstm.setInt(12, pautaEvaluacion.getItem12());
			pstm.setInt(13, pautaEvaluacion.getItem13());
			pstm.setInt(14, pautaEvaluacion.getItem14());
			pstm.setInt(15, pautaEvaluacion.getItem15());
			
			pstm.setInt(16, pautaEvaluacion.getItem16());
			pstm.setInt(17, pautaEvaluacion.getItem17());
			pstm.setInt(18, pautaEvaluacion.getItem18());
			pstm.setInt(19, pautaEvaluacion.getItem19());
			pstm.setInt(20, pautaEvaluacion.getItem20());
			
			pstm.setInt(21, pautaEvaluacion.getItem21());
			pstm.setInt(22, pautaEvaluacion.getItem22());
			pstm.setInt(23, pautaEvaluacion.getItem23());
			pstm.setInt(24, pautaEvaluacion.getItem24());
			pstm.setInt(25, pautaEvaluacion.getItem25());
			
			pstm.setInt(26, pautaEvaluacion.getItem26());
			pstm.setInt(27, pautaEvaluacion.getItem27());
			pstm.setInt(28, pautaEvaluacion.getItem28());
			pstm.setInt(29, pautaEvaluacion.getItem29());
			pstm.setInt(30, pautaEvaluacion.getItem30());
			
			pstm.setInt(31, pautaEvaluacion.getItem31());
			
			pstm.setBoolean(32, pautaEvaluacion.getNuevamente());
			pstm.setInt(33, pautaEvaluacion.getExperiencia());
			pstm.setString(34, pautaEvaluacion.getComentario());
			pstm.setTimestamp(35, tsCreacion);
			
			pstm.setDouble(36, pautaEvaluacion.getCalidad());
			pstm.setDouble(37, pautaEvaluacion.getCompromiso());
			pstm.setDouble(38, pautaEvaluacion.getVinculacion());
			pstm.setDouble(39, pautaEvaluacion.getValoracion());
			pstm.setDouble(40, pautaEvaluacion.getPtje_nota());
			
			pstm.setDouble(41, pautaEvaluacion.getNota());
			
			//WHERE
			pstm.setInt(42, socio.getRut_socio());
			pstm.setInt(43, gae.getId_gae());
			pstm.setInt(44, gae.getRut_gae());
			pstm.setInt(45, pautaEvaluacion.getId_pauta());
			
			result = pstm.executeUpdate();
			pstm.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error en la clase PautaEvaluacionDB -> modificarPautaEvaluacion -> "+ ex.getMessage());
		}		
		return result;
	}
	
	@Override
	public int eliminarPautaEvaluacion(SocioTO socio, GaeTO gae){
		PreparedStatement pstm = null;
		int result = 0;
		
		String query =  " DELETE FROM pauta_evaluacion "+
						" WHERE rut_socio=? AND id_gae=? AND rut_gae=? ";
		try{
			pstm = this.conn.prepareStatement(query);
			
			pstm.setInt(1, socio.getRut_socio());
			pstm.setInt(2, gae.getId_gae());
			pstm.setInt(3, gae.getRut_gae());
			
			result = pstm.executeUpdate();
			pstm.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error en la clase PautaEvaluacionDB -> eliminarPautaEvaluacion -> "+ ex.getMessage());
		}		
		return result;
	}
	@Override
	public int eliminarPautaEluacionGAE(int id_gae, int rut_gae){
		PreparedStatement pstm = null;
		int result = 0;
		
		String query =  " DELETE FROM pauta_evaluacion "+
						" WHERE id_gae=? AND rut_gae=? ";
		try{
			pstm = this.conn.prepareStatement(query);
			
			pstm.setInt(1, id_gae);
			pstm.setInt(2, rut_gae);
			
			result = pstm.executeUpdate();
			pstm.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error en la clase PautaEvaluacionDB -> eliminarPautaEluacionGAE -> "+ ex.getMessage());
		}		
		return result;
	}
	
	@Override
	public int eliminarTODOPautaEvaluacionSocio(int rut){
		PreparedStatement pstm = null;
		int result = 0;
		
		String query =  " DELETE FROM pauta_evaluacion "+
						" WHERE rut_socio=? ";
		try{
			pstm = this.conn.prepareStatement(query);
			
			pstm.setInt(1, rut);
			
			result = pstm.executeUpdate();
			pstm.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error en la clase PautaEvaluacionDB -> eliminarTODOPautaEvaluacionSocio -> "+ ex.getMessage());
		}		
		return result;
	}
	
	@Override
	public int reAsignarPautaEvaluacionGAE(GaeTO gaeOriginal, GaeTO gaeNuevo){
		PreparedStatement pstm = null;
		int result = 0;
		
		String query =  " UPDATE pauta_evaluacion " +
						" SET id_gae=?, rut_gae=? "+
						" WHERE id_gae=? AND rut_gae=? ";
		try{
			pstm = this.conn.prepareStatement(query);
			
			pstm.setInt(1, gaeNuevo.getId_gae());
			pstm.setInt(2, gaeNuevo.getRut_gae());
			pstm.setInt(3, gaeOriginal.getRut_gae());
			pstm.setInt(4, gaeOriginal.getRut_gae());
			
			result = pstm.executeUpdate();
			pstm.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error en la clase PautaEvaluacionDB -> reAsignarPautaEvaluacionGAE -> "+ ex.getMessage());
		}		
		return result;
	}
	
	@Override
	public List<PautaEvaluacionTO> obtenerPautaEvaluacionGae(GaeTO gae){
		
		//PautaEvaluacionTO pauta = new PautaEvaluacionTO();
		List<PautaEvaluacionTO> pautas = new ArrayList<PautaEvaluacionTO>();
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		String query = " SELECT "+CAMPOS_PAUTA+
					   " FROM pauta_evaluacion "+
					   " WHERE id_gae=? AND rut_gae=? " +
					   " ORDER BY id_pauta ";
		
		try
		{
			pstmt = conn.prepareStatement(query);
			
			pstmt.setInt(1, gae.getId_gae());
			pstmt.setInt(2, gae.getRut_gae());
			rs = pstmt.executeQuery();
			
			while(rs.next()){				
				//pauta = resultSet_a_PautaEvaluacionTO(rs);
				pautas.add(resultSet_a_PautaEvaluacionTO(rs));
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException sqle) {
			System.out.println("Error en "+this.getClass().getCanonicalName()+" -> obtenerPautaEvaluacionGae : " + sqle.getMessage());
		}
		
		return pautas;
	}
	
	@Override
	public List<PautaEvaluacionTO> obtenerPautaAsociadaGaeSocio(SocioTO socio, GaeTO gae){
		
		//PautaEvaluacionTO pauta = new PautaEvaluacionTO();
		List<PautaEvaluacionTO> pautas = new ArrayList<PautaEvaluacionTO>();
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		String query = " SELECT "+CAMPOS_PAUTA+
					   " FROM pauta_evaluacion "+
					   " WHERE rut_socio=? AND id_gae=? AND rut_gae=? " +
					   " ORDER BY id_pauta ";
		
		try
		{
			pstmt = conn.prepareStatement(query);
			
			pstmt.setInt(1, socio.getRut_socio());
			pstmt.setInt(2, gae.getId_gae());
			pstmt.setInt(3, gae.getRut_gae());
			rs = pstmt.executeQuery();
			
			while(rs.next()){				
				//pauta = resultSet_a_PautaEvaluacionTO(rs);
				pautas.add(resultSet_a_PautaEvaluacionTO(rs));
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException sqle) {
			System.out.println("Error en "+this.getClass().getCanonicalName()+" -> obtenerPautaAsociadaGaeSocio : " + sqle.getMessage());
		}
		
		return pautas;
	}
	
	@Override
	public List<PautaEvaluacionTO> obtenerPautaEvaluacionGae_Realizada(GaeTO gae){
		List<PautaEvaluacionTO> pautas = new ArrayList<PautaEvaluacionTO>();
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		String query = " SELECT "+CAMPOS_PAUTA+
					   " FROM pauta_evaluacion "+
					   " WHERE id_gae=? AND rut_gae=? AND item_1>-1" +
					   " ORDER BY id_pauta ";
		try
		{
			pstmt = conn.prepareStatement(query);
			
			pstmt.setInt(1, gae.getId_gae());
			pstmt.setInt(2, gae.getRut_gae());
			rs = pstmt.executeQuery();
			
			while(rs.next()){
				pautas.add(resultSet_a_PautaEvaluacionTO(rs));
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException sqle) {
			System.out.println("Error en "+this.getClass().getCanonicalName()+" -> obtenerPautaEvaluacionGae_Realizada : " + sqle.getMessage());
		}
		
		return pautas;
	}
	
	@Override
	public List<PautaEvaluacionTO> obtenerPautaEvaluacionCurso_Realizada(CursoTO curso){
		List<PautaEvaluacionTO> pautas = new ArrayList<PautaEvaluacionTO>();
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		/*String query =  " SELECT "+CAMPOS_PAUTA+
						" FROM	" +
						" (select * " +
						" from curso" +
						" inner join gae on curso.id_curso = gae.id_curso " +
						" where curso.anio = ? and curso.carrera = ?) as r " +
						" inner join pauta_evaluacion as p on r.id_gae = p.id_gae and r.rut_gae = p.rut_gae " +
						" ORDER BY id_pauta ";*/
		
		String query =  " SELECT id_pauta, rut_socio, r.id_gae, r.rut_gae, item_1, item_2, item_3, "+ 
						" item_4, item_5, item_6, item_7, item_8, item_9, item_10, item_11, "+
						" item_12, item_13, item_14, item_15, item_16, item_17, item_18, "+
						" item_19, item_20, item_21, item_22, item_23, item_24, item_25, "+
						" item_26, item_27, item_28, item_29, item_30, item_31, nuevamente, "+
						" experiencia, comentario, fecha_hora, calidad, compromiso, vinculacion, "+
						" valoracion, ptje_nota, nota "+
						" FROM "+
						" (SELECT gae.id_gae, gae.rut_gae FROM gae INNER JOIN curso ON curso.id_curso = gae.id_curso WHERE curso.anio = ? AND curso.carrera = ?) AS r "+ 
						" INNER JOIN pauta_evaluacion AS p ON r.id_gae = p.id_gae AND r.rut_gae = p.rut_gae ";
		
		try
		{
			pstmt = conn.prepareStatement(query);
			
			pstmt.setInt(1, curso.getAnio());
			pstmt.setString(2, curso.getCarrera());
			rs = pstmt.executeQuery();
			
			while(rs.next()){
				pautas.add(resultSet_a_PautaEvaluacionTO(rs));
			}
			rs.close();
			pstmt.close();
		}
		catch (SQLException sqle) {
			System.out.println("Error en "+this.getClass().getCanonicalName()+" -> obtenerPautaEvaluacionCurso_Realizada : " + sqle.getMessage());
		}
		
		return pautas;
	}
		
		@Override
		public double promedioPautasGae(int rut_socio, int id_gae, int rut_gae)
		{
			double resp = -1;
			List<Double> resp2 = new ArrayList<Double>();
			PreparedStatement pstmt = null;
			ResultSet rs = null;
			
			//String query = " SELECT ROUND (AVG(nota),2) AS promedio FROM pauta_evaluacion WHERE rut_socio = ? AND id_gae = ? AND rut_gae = ?";
			String query = " SELECT nota FROM pauta_evaluacion WHERE rut_socio = ? AND id_gae = ? AND rut_gae = ?";
			
			try{						
				pstmt = conn.prepareStatement(query);						
				
				pstmt.setInt(1, rut_socio);
				pstmt.setInt(2, id_gae);
				pstmt.setInt(3, rut_gae);
				
				rs = pstmt.executeQuery();
				/*
				if(rs.next())
					resp = rs.getDouble("promedio");
				*/
				while(rs.next())
					resp2.add(rs.getDouble("nota"));
				
				double aux=0;
				int bandera=0;
				for(int i=0;i<2;i++){
					if(resp2.get(i)>0){
						aux = aux + resp2.get(i);
						bandera++;
					}
				}
				resp=aux/bandera;
				
				rs.close();			
			}
			catch (SQLException sqle) {
				System.out.print("Error en PautaEvaluacionDB -> obtenerPromedioGae() : " + sqle.getMessage());
			}
			finally{
				if (pstmt != null) {
			          try {
			               pstmt.close();
			               
			          } catch (SQLException e) {
			               e.printStackTrace();
			          }
				}
			}
			return resp;
		}
}
